commonlibsse_ng\re\n/
NiAllocator.rs

1use core::ffi::{c_char, c_void};
2
3use crate::re::offsets_rtti::RTTI_NiAllocator;
4use crate::re::offsets_vtable::VTABLE_NiAllocator;
5use crate::rel::id::VariantID;
6
7#[derive(Debug)]
8#[repr(C)]
9pub struct NiAllocator {
10    pub vtable: *const NiAllocatorVtbl,
11}
12const _: () = assert!(core::mem::size_of::<NiAllocator>() == 0x8);
13
14impl NiAllocator {
15    /// Address & offset of the runtime type information (RTTI) identifier.
16    pub const RTTI: VariantID = RTTI_NiAllocator;
17
18    /// Address & offset of the virtual function table.
19    pub const VTABLE: [VariantID; 1] = VTABLE_NiAllocator;
20
21    #[inline]
22    pub fn vtable(&self) -> &NiAllocatorVtbl {
23        debug_assert!(!self.vtable.is_null());
24        unsafe { &*self.vtable }
25    }
26}
27
28/// 9 methods
29#[repr(C)]
30pub struct NiAllocatorVtbl {
31    pub Allocate: extern "C" fn(
32        this: *mut NiAllocator,
33        sizeInBytes: &mut usize,
34        alignment: &mut usize,
35        eventType: NiMemEventType,
36        provideAccurateSizeOnDeallocate: bool,
37        file: *const c_char,
38        line: i32,
39        function: *const c_char,
40    ) -> *mut c_void,
41
42    pub Deallocate: extern "C" fn(
43        this: *mut NiAllocator,
44        memory: *mut c_void,
45        eventType: NiMemEventType,
46        sizeInBytes: usize,
47    ),
48
49    pub Reallocate: extern "C" fn(
50        this: *mut NiAllocator,
51        memory: *mut c_void,
52        sizeInBytes: *mut usize,
53        alignment: *mut usize,
54        eventType: NiMemEventType,
55        provideAccurateSizeOnDeallocate: bool,
56        size_current: usize,
57        file: *const c_char,
58        line: i32,
59        function: *const c_char,
60    ) -> *mut c_void,
61
62    pub TrackAllocate: extern "C" fn(
63        this: *mut NiAllocator,
64        memory: *const c_void,
65        sizeInBytes: usize,
66        eventType: NiMemEventType,
67        file: *const c_char,
68        line: i32,
69        function: *const c_char,
70    ) -> bool,
71
72    pub TrackDeallocate: extern "C" fn(
73        this: *mut NiAllocator,
74        memory: *const c_void,
75        eventType: NiMemEventType,
76    ) -> bool,
77
78    pub Unk_06: extern "C" fn(this: *mut NiAllocator),
79
80    pub Initialize: extern "C" fn(this: *mut NiAllocator),
81
82    pub Shutdown: extern "C" fn(this: *mut NiAllocator),
83
84    pub VerifyAddress: extern "C" fn(this: *mut NiAllocator, memory: *const c_void) -> bool,
85}
86
87#[commonlibsse_ng_derive_internal::ffi_enum]
88#[repr(C)]
89#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
90pub enum NiMemEventType {
91    #[default]
92    Unknown = 0,
93    OperNew = 1,
94    OperNewArray = 2,
95    OperDelete = 3,
96    OperDeleteArray = 4,
97    Malloc = 5,
98    Realloc = 6,
99    AlignedMalloc = 7,
100    AlignedRealloc = 8,
101    Free = 9,
102    AlignedFree = 10,
103    ExternalAlloc = 11,
104    ExternalFree = 12,
105}